#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,V,speeds[100005],ans1,nums[3005],ans2;bool state[3005][3005],fast[3005],cover[3005];
struct car{
    int d,v,a;
}cars[100005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        ans1=ans2=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            scanf("%d %d %d",&cars[i].d,&cars[i].v,&cars[i].a);
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&speeds[i]);nums[i]=0;
        }
        for(int i=1;i<=n;i++){
//          cout<<i<<':';
            bool flag=0;
            fast[i]=cover[i]=0;
            for(int j=1;j<=m;j++){
                state[i][j]=0;
                if(speeds[j]<cars[i].d) continue;
                double speed=sqrt(max(cars[i].v*cars[i].v+2*cars[i].a*(speeds[j]-cars[i].d),0));

                if(speed>V){
                    flag=1;state[i][j]=1;nums[j]++;fast[i]=1;
                }
//              cout<<state[i][j]<<' ';
            }
//          cout<<endl;
            if(flag) ans1++;
        }
        for(int i=1;i<=n;i++){
            if(!fast[i]||cover[i]) continue;
            int maxx=0;
            for(int j=1;j<=m;j++){
                if(state[i][j]){
                    nums[j]--;
                    if(nums[maxx]<=nums[j]){
                        maxx=j;
                    }
                }
            }
            if(maxx){
                for(int j=i;j<=n;j++){
                    if(state[j][maxx]) cover[j]=1;
                }
            }
            ans2++;
        }
        cout<<ans1<<' '<<m-ans2<<endl;
    }


    return 0;
}
